package week_five;

public class JumpGameII_45 {
    public int jump(int[] nums) {
        //贪心，往后多看一步
        //下一步能跳的最远的位置就是当前最优解。
        int ans = 0;
        int length = nums.length;
        int max = 0;
        int next = 0;

        for (int i = 0; i < length - 1; i++) {
            max = Math.max(max, i + nums[i]);
            if (i == next) {
                next = max;
                ans++;
            }
        }

        return ans;
    }
}
